//
//  StatusRetweetedCell.swift
//  01-界面搭建
//
//  Created by Apple on 15/11/11.
//  Copyright © 2015年 Apple. All rights reserved.
//

import UIKit
/// 转发微博的 Cell
class StatusRetweetedCell: StatusCell {
    /// 微博视图模型
    /// 如果继承父类的属性
    /// 1. 需要 override
    /// 2. 不需要 super
    /// 3. 先执行父类的 didSet，再执行子类的 didSet -> 只关心 子类相关设置就够了！
    /// 微博视图模型
    
    override  var viewModel:StatusViewModel? {
        didSet{
            // 转发微博的文字
            retweetedLabel.text = viewModel?.retweetedText
            //配图行高
            pictureView.snp_updateConstraints { (make) -> Void in
                
                //根据配图数量，决定配图视图的顶部间距
                let offset = viewModel?.thumbnailsURL?.count > 0 ? StatusCellMargin : 0
                make.top.equalTo(retweetedLabel.snp_bottom).offset(offset)
            }
            
        }
        
    }
    
    
    // MARK: - 懒加载控件
    /// 背景按钮
    private lazy var backButton:UIButton = {
        let btn = UIButton()
        btn.backgroundColor = UIColor(white: 0.95, alpha: 1.0)
        return btn
    }()
    /// 转发标签
    private lazy var retweetedLabel:UILabel = UILabel(Labeltext: "转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博",
        Textcolor: UIColor.darkGrayColor(),
        Labelfont: 14,
        screenInset: StatusCellMargin)
}
// MARK: - 设置界面
extension StatusRetweetedCell {
    // 1. 添加控件
    override func setUpUI() {
        super.setUpUI()
        contentView.insertSubview(backButton, belowSubview:  pictureView)
        contentView.insertSubview(retweetedLabel, aboveSubview: backButton)
        //自动布局
        backButton.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentLabel.snp_bottom).offset(StatusCellMargin)
            make.left.right.equalTo(contentView)
            make.bottom.equalTo(bottomView.snp_top)
        }
        retweetedLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(backButton.snp_top).offset(StatusCellMargin)
            make.left.equalTo(backButton.snp_left).offset(StatusCellMargin)
        }
        pictureView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(retweetedLabel.snp_bottom).offset(StatusCellMargin)
            make.left.equalTo(retweetedLabel.snp_left)
            make.width.equalTo(300)
            make.height.equalTo(90)
        }
        
    }
    
}